<?php
include_once "../header1.php";
?>
</head>
<body>
<?php
include_once ("$basedir"."/Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("$basedir"."/index.php");
}
   
   else
   {

   if(isset($_POST['SaveChanges']))
   {
 
   require_once 'UPP.php';
   }
    $School_Id="";
	   $Exam_Name="";
	   $Year="";
   if(isset($_POST['Edit_This']))
	   {
	
	   $School_Id=$_POST['School_Id'];
	   $Exam_Name=$_POST['Exam_Name'];
	   $Year=$_POST['Year'];
	 
	 
	   $_SESSION['Exam_Name']=$Exam_Name;
   $_SESSION['School_Id']=$School_Id;
	  $_SESSION['Year']=$Year;
 if( $School_Id=="Select One"||$Exam_Name=="Select One"||$Year=="Select One")
	   {
		    
	$_SESSION['errorin1']="Please select the Exam name,School_Id and Year!";
}
	   else
	   {
	   $result=mysql_query("SELECT * FROM exam WHERE School_Id='$School_Id' AND Exam_Name='$Exam_Name' AND Year='$Year'");
	   if(mysql_num_rows($result)==0)
   {
$_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
	 }  
   ?>
    <?php

include_once "../header2.php";


?>
<?php
include_once "topmenu.php";
?>
<div class="left">
  
<div class="articles">
<br/><form action="#" method="POST">
  <table width="562" border="0">
    <tr>
      <th colspan="4"  scope="row"><?php
		if(isset($_POST['Edit_This'])||isset($_POST['SaveChanges']))
{
 if(isset($_SESSION['error']))
	{
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errorin']))
	{
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['errorin1']))
	{
		echo $_SESSION['errorin1'];
		unset($_SESSION['errorin1']);
	}
	if(isset($_SESSION['errornorow']))
	{
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
}
		?>
		</th>
      </tr>
    <tr>
      <th width="51"  scope="row">&nbsp;</th>
      <th width="127"  scope="row">School Id:</th>
      <td width="92"><select name="School_Id">
        <?php
	  
	  if(isset($_POST['Edit_This']))
	  {
	 echo '<option value="'.$School_Id.'">'.$School_Id.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $exa=mysql_query("SELECT DISTINCT(School_Id) FROM exam");
	  
  while($row=mysql_fetch_array($exa))
  {
	 $Sch_Id=$row['School_Id'];
if($School_Id!=$Sch_Id)
{
	  echo '<option value="'.$Sch_Id.'">'.$Sch_Id.'</option>';
  }
  }
	  ?>
      </select></td>
      <td width="274">&nbsp;</td>
    </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <th scope="row">Exam Name:</th>
      <td><select name="Exam_Name">
        <?php
	  
	  if(isset($_POST['Edit_This']))
	  {
	 echo '<option value="'.$Exam_Name.'">'.$Exam_Name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $exa=mysql_query("SELECT DISTINCT(Exam_Name) FROM exam");
	  
  while($row=mysql_fetch_array($exa))
  {
	 $Exa_Name=$row['Exam_Name'];
if($Exam_Name!=$Exa_Name)
{
	  echo '<option value="'.$Exa_Name.'">'.$Exa_Name.'</option>';
  }
  }
	  ?>
      </select></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <th scope="row">Year:</th>
      <td><select name="Year">
        <?php
	  
	  if(isset($_POST['Edit_This']))
	  {
	 echo '<option value="'.$Year.'">'.$Year.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	 $exa=mysql_query("SELECT DISTINCT(Year) FROM exam");
	  
  while($row=mysql_fetch_array($exa))
  {
  $Yea=$row['Year'];
if($Year!=$Yea)
{
	  echo '<option value="'.$Yea.'">'.$Yea.'</option>';
  }

	 } ?>
      </select></td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <br/>
      <a href="UpdateExam.php">Reset</a>|
    <input name="Edit_This" align="middle" type="submit" value="Edit this" />
      <br/>
  
</form>
<form action="#" method="POST">
    <?php 
	if(isset($_POST['Edit_This']))
	   {
	   if($School_Id!="Select One"&&$Exam_Name!="Select One"&&$Year!="Select One")
	   {
   $result=mysql_query("SELECT * FROM exam WHERE School_Id='$School_Id' AND Exam_Name='$Exam_Name' AND Year='$Year'");
  echo '<table width="354" border="0">';
 while($row=mysql_fetch_array($result))
  {
    
$s_name=$row['School_Id'];
$Exam=$row['Exam_Name'];
$Ye=$row['Year'];
$No_Of_Sat=$row['No_Of_Sat_Students'];
$No_Of_Passed=$row['No_Of_Passed_Students'];
	
   ?>
   <?php
      echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "School Id:";
		echo '</th>';
        echo '<td width="144">';
		echo '<div contenteditable>';
		echo "<input type='text' name='School_Idc' value='$s_name'/>";
		echo '</div>';
		echo '</td>';
      echo '</tr>';
	  
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Exam Name:";
		echo '</th>';
        echo '<td>';
		echo '<div contenteditable>';
		echo "<input type='text' name='Exam_Namec' value='$Exam'/>";
		echo '</div>';
		echo '</td>';
      echo '</tr>';
	  
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Year:";
		echo '</th>';
        echo '<td>';
		echo '<div contenteditable>';
		echo "<input type='text' name='Yearc' value='$Ye'/>";
		echo '</div>';
		echo '</td>';
		 echo '</tr>';
		 
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number Of Sat_Students:";
		echo '</th>';
       echo '<td>';
	   echo '<div contenteditable>';
	   echo "<input type='text' name='No_Of_Sat_Students' value='$No_Of_Sat'/>";
	   echo '</div>';
	   echo '</td>';
      echo '</tr>';
	  
     echo '<tr>';
       echo '<th height="44" scope="row">';
	   echo "Number Of Passed_Student:"; 
	    echo '</th>';
	  echo '<td>';
	   echo '<div contenteditable>';
	   echo "<input type='text' name='No_Of_Passed_Students' value='$No_Of_Passed'/>";
	   echo '</div>';
	   echo '</td>';
	   echo '</tr>';
	 }
   echo '</table>';
   
   echo "</br>";
   echo '<input name="SaveChanges" align="middle" type="submit" value="Save changes" />';
 }
	   }
	   ?>
       </form>
   
</div>
</div>

<div class="rightmenu"> 
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php

}
?>
</body>
</html>